﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Utils.Configs;
using UniMana.Data;

namespace UniMana.Data
{
    public class Personnel_AttendanceDetailV2Info
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/

            private DBMain m_data = new DBMain();

            #region [Properties - Thuộc tính]
            public Personnel_Attendance_DetailV2 Properties
            {
                get { return m_bds.Current as Personnel_Attendance_DetailV2; }
            }
            #endregion

            public Personnel_AttendanceDetailV2Info(int _attendanceKey, string _personnelKey, int shiftKey)
            {
                var IQuery = m_data.m_DCSave.Personnel_Attendance_DetailV2s.Where(p => p.Personnel_AttendanceKey == _attendanceKey 
                                                                           && p.Personnel_PersonnelKey == Guid.Parse(_personnelKey)
                                                                           && p.Catalogue_ShiftsKey == shiftKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Personnel_Attendance_DetailV2();
                    Row.Personnel_AttendanceKey = _attendanceKey;
                    Row.Personnel_PersonnelKey = Guid.Parse(_personnelKey);
                    Row.Catalogue_ShiftsKey = shiftKey;
                    m_bds.Add(Row);
                }
            }
    }
}
